package cn.xshi.bpm.web;

import cn.xshi.bpm.service.ActRuTaskService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.base.BaseSearch;
import cn.xshi.bpm.model.ActRuTask;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
 * @Desc 运行时任务
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Api(value = "运行时任务",description = "运行时任务", tags = "运行时任务")
@RestController
@RequestMapping("/actRuTask")
public class ActRuTaskController extends BaseAction {

    @Resource
    private ActRuTaskService actRuTaskService;

    /**
     * 查询并分页
     * @param baseSearch
     */
    @ApiOperation(value="查询并分页", notes="查询并分页")
    @PostMapping(value="/list")
    @Auth(value = "/actRuTask/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
    public BasePage<List<ActRuTask>> getActRuTaskListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
        Map<String, Object> condition = baseSearch.convert();
        commonHPager(baseSearch);
        List<ActRuTask> actRuTaskList = actRuTaskService.getActRuTaskListByCondition(condition);
        PageInfo<ActRuTask> page = new PageInfo<ActRuTask>(actRuTaskList);
        return outPageBootStr(page,baseSearch);
    }

    /**
     * 查询单条记录
     * @param id
     */
    @ApiOperation(value="查询单条记录", notes="查询单条记录")
    @GetMapping(value="/get/{id}")
    @Auth(value = "/actRuTask/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
    public BaseResult<ActRuTask> getActRuTaskById(@PathVariable("id")String id){
        ActRuTask actRuTask = actRuTaskService.getActRuTaskById(id);
        return outDataStr(actRuTask);
    }

    /**
     * 删除运行时任务
     * @param id
     * @param procInstId
     * @return
     */
    @ApiOperation(value="删除运行时任务", notes="删除运行时任务")
    @DeleteMapping(value="/delete")
    public BaseResult delActRuTask(String id,String procInstId){
        int i = actRuTaskService.delActRuTask(id);
        if(i>0){
            return BaseResult.success();
        }else {
            return BaseResult.fail();
        }
    }
}
